
Imports System.Data
Imports System.ComponentModel
Imports System.Data.SqlClient
'Imports SplitDataGrid.ScrollLessDataGrid
Public Class frmProductDistributionReport
    Inherits System.Windows.Forms.Form
    'Dim ScrollLessDataGrid As SplitDataGrid.ScrollLessDataGrid

    Dim icpEdit As ICproductsEdit

    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdRefresh As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExport As DevComponents.DotNetBar.ButtonX
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents cmbManuf As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbSubCat As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbCategory As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbBrand As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbDepartment As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbIndicator As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cmbYear As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Dim CompanyCode As Integer = CompanyID
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'Me call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents cbActive As System.Windows.Forms.CheckBox
    Friend WithEvents dgProduct As System.Windows.Forms.DataGrid
    Friend WithEvents ttHelp As System.Windows.Forms.ToolTip
    Friend WithEvents crICproductDistribution1 As crICproductDistribution
    Friend WithEvents cbCost As System.Windows.Forms.CheckBox
    Friend WithEvents SFdlg As System.Windows.Forms.SaveFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.dgProduct = New System.Windows.Forms.DataGrid()
        Me.cbActive = New System.Windows.Forms.CheckBox()
        Me.ttHelp = New System.Windows.Forms.ToolTip(Me.components)
        Me.crICproductDistribution1 = New crICproductDistribution()
        Me.cbCost = New System.Windows.Forms.CheckBox()
        Me.SFdlg = New System.Windows.Forms.SaveFileDialog()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdRefresh = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExport = New DevComponents.DotNetBar.ButtonX()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.cmbManuf = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbSubCat = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbCategory = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbBrand = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbDepartment = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbIndicator = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.cmbYear = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'dgProduct
        '
        Me.dgProduct.BackColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgProduct.CaptionVisible = False
        Me.dgProduct.DataMember = ""
        Me.dgProduct.HeaderBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(128, Byte), Integer))
        Me.dgProduct.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgProduct.Location = New System.Drawing.Point(6, 67)
        Me.dgProduct.Name = "dgProduct"
        Me.dgProduct.ReadOnly = True
        Me.dgProduct.Size = New System.Drawing.Size(1193, 382)
        Me.dgProduct.TabIndex = 13
        Me.ttHelp.SetToolTip(Me.dgProduct, "Click on Column Header to Sort.  Click in grid to select product")
        '
        'cbActive
        '
        Me.cbActive.AutoSize = True
        Me.cbActive.BackColor = System.Drawing.Color.Transparent
        Me.cbActive.Checked = True
        Me.cbActive.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cbActive.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.cbActive.Location = New System.Drawing.Point(573, 461)
        Me.cbActive.Name = "cbActive"
        Me.cbActive.Size = New System.Drawing.Size(171, 22)
        Me.cbActive.TabIndex = 18
        Me.cbActive.Text = "Include Committed Qty"
        Me.cbActive.UseVisualStyleBackColor = False
        '
        'cbCost
        '
        Me.cbCost.AutoSize = True
        Me.cbCost.BackColor = System.Drawing.Color.Transparent
        Me.cbCost.Checked = True
        Me.cbCost.CheckState = System.Windows.Forms.CheckState.Checked
        Me.cbCost.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.cbCost.Location = New System.Drawing.Point(756, 461)
        Me.cbCost.Name = "cbCost"
        Me.cbCost.Size = New System.Drawing.Size(91, 22)
        Me.cbCost.TabIndex = 50
        Me.cbCost.Text = "Show Cost"
        Me.cbCost.UseVisualStyleBackColor = False
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(941, 461)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 27)
        Me.cmdPrint.TabIndex = 267
        Me.cmdPrint.Text = "Print"
        '
        'cmdRefresh
        '
        Me.cmdRefresh.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRefresh.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRefresh.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRefresh.Location = New System.Drawing.Point(1029, 461)
        Me.cmdRefresh.Name = "cmdRefresh"
        Me.cmdRefresh.Size = New System.Drawing.Size(82, 27)
        Me.cmdRefresh.TabIndex = 268
        Me.cmdRefresh.Text = "Refresh"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(1117, 461)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 266
        Me.cmdExit.Text = "Exit"
        '
        'cmdExport
        '
        Me.cmdExport.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExport.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExport.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExport.Location = New System.Drawing.Point(853, 461)
        Me.cmdExport.Name = "cmdExport"
        Me.cmdExport.Size = New System.Drawing.Size(82, 27)
        Me.cmdExport.TabIndex = 267
        Me.cmdExport.Text = "Export"
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.BackColor = System.Drawing.Color.Transparent
        Me.Label9.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label9.Location = New System.Drawing.Point(838, 15)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(89, 18)
        Me.Label9.TabIndex = 277
        Me.Label9.Text = "Sub Category"
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.BackColor = System.Drawing.Color.Transparent
        Me.Label8.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label8.Location = New System.Drawing.Point(657, 15)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(63, 18)
        Me.Label8.TabIndex = 276
        Me.Label8.Text = "Category"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(109, 15)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(83, 18)
        Me.Label3.TabIndex = 275
        Me.Label3.Text = "Department"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.BackColor = System.Drawing.Color.Transparent
        Me.Label6.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label6.Location = New System.Drawing.Point(289, 15)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(44, 18)
        Me.Label6.TabIndex = 274
        Me.Label6.Text = "Brand"
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.BackColor = System.Drawing.Color.Transparent
        Me.Label7.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label7.Location = New System.Drawing.Point(472, 15)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(92, 18)
        Me.Label7.TabIndex = 273
        Me.Label7.Text = "Manufacturer"
        '
        'cmbManuf
        '
        Me.cmbManuf.DisplayMember = "Text"
        Me.cmbManuf.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbManuf.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbManuf.ItemHeight = 19
        Me.cmbManuf.Location = New System.Drawing.Point(475, 60)
        Me.cmbManuf.Name = "cmbManuf"
        Me.cmbManuf.Size = New System.Drawing.Size(178, 25)
        Me.cmbManuf.TabIndex = 282
        '
        'cmbSubCat
        '
        Me.cmbSubCat.DisplayMember = "Text"
        Me.cmbSubCat.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbSubCat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbSubCat.ItemHeight = 19
        Me.cmbSubCat.Location = New System.Drawing.Point(841, 60)
        Me.cmbSubCat.Name = "cmbSubCat"
        Me.cmbSubCat.Size = New System.Drawing.Size(178, 25)
        Me.cmbSubCat.TabIndex = 281
        '
        'cmbCategory
        '
        Me.cmbCategory.DisplayMember = "Text"
        Me.cmbCategory.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbCategory.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbCategory.ItemHeight = 19
        Me.cmbCategory.Location = New System.Drawing.Point(658, 60)
        Me.cmbCategory.Name = "cmbCategory"
        Me.cmbCategory.Size = New System.Drawing.Size(178, 25)
        Me.cmbCategory.TabIndex = 280
        '
        'cmbBrand
        '
        Me.cmbBrand.DisplayMember = "Text"
        Me.cmbBrand.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbBrand.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbBrand.ItemHeight = 19
        Me.cmbBrand.Location = New System.Drawing.Point(292, 60)
        Me.cmbBrand.Name = "cmbBrand"
        Me.cmbBrand.Size = New System.Drawing.Size(178, 25)
        Me.cmbBrand.TabIndex = 279
        '
        'cmbDepartment
        '
        Me.cmbDepartment.DisplayMember = "Text"
        Me.cmbDepartment.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbDepartment.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbDepartment.ItemHeight = 19
        Me.cmbDepartment.Location = New System.Drawing.Point(109, 60)
        Me.cmbDepartment.Name = "cmbDepartment"
        Me.cmbDepartment.Size = New System.Drawing.Size(178, 25)
        Me.cmbDepartment.TabIndex = 278
        '
        'cmbIndicator
        '
        Me.cmbIndicator.DisplayMember = "Text"
        Me.cmbIndicator.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbIndicator.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbIndicator.ItemHeight = 19
        Me.cmbIndicator.Location = New System.Drawing.Point(1021, 36)
        Me.cmbIndicator.Name = "cmbIndicator"
        Me.cmbIndicator.Size = New System.Drawing.Size(178, 25)
        Me.cmbIndicator.TabIndex = 281
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(1021, 15)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(63, 18)
        Me.Label1.TabIndex = 277
        Me.Label1.Text = "Indicator"
        '
        'cmbYear
        '
        Me.cmbYear.DisplayMember = "Text"
        Me.cmbYear.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbYear.ItemHeight = 19
        Me.cmbYear.Location = New System.Drawing.Point(9, 36)
        Me.cmbYear.Name = "cmbYear"
        Me.cmbYear.Size = New System.Drawing.Size(93, 25)
        Me.cmbYear.TabIndex = 281
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(9, 15)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(34, 18)
        Me.Label2.TabIndex = 277
        Me.Label2.Text = "Year"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.Label9)
        Me.GroupPanel1.Controls.Add(Me.cmbYear)
        Me.GroupPanel1.Controls.Add(Me.cbActive)
        Me.GroupPanel1.Controls.Add(Me.cmbIndicator)
        Me.GroupPanel1.Controls.Add(Me.cbCost)
        Me.GroupPanel1.Controls.Add(Me.cmdExport)
        Me.GroupPanel1.Controls.Add(Me.Label7)
        Me.GroupPanel1.Controls.Add(Me.cmdPrint)
        Me.GroupPanel1.Controls.Add(Me.Label6)
        Me.GroupPanel1.Controls.Add(Me.cmdRefresh)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.Label8)
        Me.GroupPanel1.Controls.Add(Me.dgProduct)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(1212, 524)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 283
        Me.GroupPanel1.Text = "Product Distribution Report"
        '
        'frmProductDistributionReport
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(1212, 524)
        Me.ControlBox = False
        Me.Controls.Add(Me.cmbManuf)
        Me.Controls.Add(Me.cmbSubCat)
        Me.Controls.Add(Me.cmbCategory)
        Me.Controls.Add(Me.cmbBrand)
        Me.Controls.Add(Me.cmbDepartment)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.Color.DarkTurquoise
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(5, 30)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmProductDistributionReport"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub ICproducts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ICdata As New ICdataLogic
        Dim ds5 As DataSet = ICdata.ListFinancialYears()
        cmbYear.DataSource = ds5.Tables(0)
        cmbYear.ValueMember = "YearNo"
        cmbYear.DisplayMember = "YearCode"
        If Now.Month <= 4 Then
            cmbYear.SelectedValue = Now.Year
        Else
            cmbYear.SelectedValue = Now.Year + 1
        End If
        LoadGroupCombos(CompanyCode)
    End Sub
    Private Sub LoadGroupCombos(ByVal CompanyCode As Integer)
        Dim ICdata As New ICdataLogic
        Dim dRow As DataRow

        Dim ds, dss, ds3, ds2 As DataSet
        ds = ICdata.GetProductGroups(CompanyCode, 1)
        cmbDepartment.DataSource = ds.Tables(0)
        cmbDepartment.ValueMember = "GroupID"
        cmbDepartment.DisplayMember = "GroupName"
        cmbDepartment.SelectedValue = 0
        '
        ds = ICdata.GetProductGroups(CompanyCode, 2)
        cmbBrand.DataSource = ds.Tables(0)
        cmbBrand.ValueMember = "GroupID"
        cmbBrand.DisplayMember = "GroupName"
        cmbBrand.SelectedValue = 0
        '
        ds = ICdata.GetProductGroups(CompanyCode, 3)
        cmbManuf.DataSource = ds.Tables(0)
        cmbManuf.ValueMember = "GroupID"
        cmbManuf.DisplayMember = "GroupName"
        cmbManuf.SelectedValue = 0
        '
        ds = ICdata.GetProductGroups(CompanyCode, 4)
        cmbCategory.DataSource = ds.Tables(0)
        cmbCategory.ValueMember = "GroupID"
        cmbCategory.DisplayMember = "GroupName"
        cmbCategory.SelectedValue = 0
        '
        ds = ICdata.GetProductGroups(CompanyCode, 5)
        cmbSubCat.DataSource = ds.Tables(0)
        cmbSubCat.ValueMember = "GroupID"
        cmbSubCat.DisplayMember = "GroupName"
        cmbSubCat.SelectedValue = 0
        '
        dss = ICdata.GetProductIndicator()
        cmbIndicator.DataSource = ds2.Tables("LEVEL")
        cmbIndicator.ValueMember = "IndicatorID"
        cmbIndicator.DisplayMember = "IndicatorName"
        cmbIndicator.SelectedValue = 0

        ICdata = Nothing
    End Sub
    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Dim WhereClause As String = ""
        Dim PromotFlag As Integer
        Dim KitFlag As Integer
        Dim ActiveFlag As Integer
        Dim ProdType As Integer
        If cbActive.Checked = True Then
            ActiveFlag = 1
        Else
            ActiveFlag = 0
        End If

        If cmbDepartment.SelectedValue <> 0 Then
            WhereClause += " where Group1Code=" & cmbDepartment.SelectedValue
        End If
        If cmbBrand.SelectedValue <> 0 Then
            If WhereClause.Trim <> "" Then
                WhereClause += " and Group2Code=" & cmbBrand.SelectedValue
            Else
                WhereClause += " where Group2Code=" & cmbBrand.SelectedValue
            End If
        End If
        If cmbManuf.SelectedValue <> 0 Then
            If WhereClause.Trim <> "" Then
                WhereClause += " and Group3Code=" & cmbManuf.SelectedValue
            Else
                WhereClause += " where Group3Code=" & cmbManuf.SelectedValue
            End If
        End If
        If cmbCategory.SelectedValue <> 0 Then
            If WhereClause.Trim <> "" Then
                WhereClause += " and Group4Code=" & cmbCategory.SelectedValue
            Else
                WhereClause += " where Group4Code=" & cmbCategory.SelectedValue
            End If
        End If
        If cmbSubCat.SelectedValue <> 0 Then
            If WhereClause.Trim <> "" Then
                WhereClause += " and Group5Code=" & cmbSubCat.SelectedValue
            Else
                WhereClause += " where Group5Code=" & cmbSubCat.SelectedValue
            End If
        End If
        Dim wc As String

        If cmbIndicator.SelectedValue <> 0 Then
            If cmbIndicator.SelectedValue <> 5 Then
                wc = " where ProductIndicator=" & cmbIndicator.SelectedValue
            Else
                wc = " where ProductIndicator=" & cmbIndicator.SelectedValue & " or Discontinued =  " & cmbYear.SelectedValue - 1
            End If
        End If
        'If ComboBox1.SelectedValue <> 0 Then
        '    If ComboBox1.SelectedValue <> 5 Then
        '        'If wc.Trim <> "" Then
        '        wc = " where ProductIndicator=" & ComboBox1.SelectedValue
        '        '& " and ProductIndicator=" & ComboBox1.SelectedValue
        '        'Else
        '        '    wc += " where c.ProductIndicator=" & ComboBox1.SelectedValue
        '        '    '& " and ProductIndicator=" & ComboBox1.SelectedValue
        '        'End If
        '    End If
        'End If

        'If cmbIndicator.SelectedValue = 5 Then
        '    If WhereClause.Trim <> "" Then
        '        WhereClause += " and ((Discontinued<=" & cmbYear.SelectedValue & " and Discontinued>0 ) ) "
        '    Else
        '        WhereClause += "((Discontinued<=" & cmbYear.SelectedValue & " and Discontinued>0 ) ) "
        '    End If
        'End If
        Dim ICdata As New ICdataLogic
        Dim ds As DataSet
        'MessageBox.Show(cmbGroup5.SelectedValue & "|" & cmbGroup1.SelectedValue & "|" & ComboBox1.SelectedValue)
        ds = ICdata.GetProductDistributione(WhereClause, ActiveFlag, cmbYear.SelectedValue, wc)
        Dim drow As DataRow
        For Each drow In ds.Tables(0).Rows
            If cbCost.Checked = False Then
                drow("Cost") = System.DBNull.Value
            End If
        Next
        '
        dgProduct.DataSource = ds.Tables(0)
        With dgProduct
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False
        dgformat(ds.Tables(0).Rows.Count)
        ICdata = Nothing

    End Sub
    Private Sub dgformat(ByVal RowCount As Integer)
        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .MappingName = "PRODUCT"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With
        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 0
        cs1.MappingName = "PRODUCTID"
        cs1.HeaderText = "ID"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 100
        cs1.MappingName = "PRODUCTCODE"
        cs1.HeaderText = "CODE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 200
        cs1.MappingName = "SHORTDESCRIPTIONE"
        cs1.HeaderText = "DESCRIPTION"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 60
        cs1.MappingName = "PRICE"
        cs1.HeaderText = "PRICE"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        If UserGroupID <> 10 And UserGroupID <> 7 Then
            cs1 = New DataGridTextBoxColumn
            cs1.Width = 60
            cs1.MappingName = "COST"
            cs1.HeaderText = "COST"
            cs1.NullText = ""
            cs1.ReadOnly = True
            cs1.Alignment = HorizontalAlignment.Right
            grdTableStyle.GridColumnStyles.Add(cs1)
        End If
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT1QTY"
        cs1.HeaderText = "AL RAI"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT2QTY"
        cs1.HeaderText = "SALMIYA"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT3QTY"
        cs1.HeaderText = "SHARQ"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT4QTY"
        cs1.HeaderText = "AVENUES"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT14QTY"
        cs1.HeaderText = "N.S.INV"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT6QTY"
        cs1.HeaderText = "FWR-WH"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT7QTY"
        cs1.HeaderText = "SWS-WH"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT13QTY"
        cs1.HeaderText = "SWS-SM"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT8QTY"
        cs1.HeaderText = "UTG-WH"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT11QTY"
        cs1.HeaderText = "UTG-SM"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT9QTY"
        cs1.HeaderText = "TP-WH"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 70
        cs1.MappingName = "DPT12QTY"
        cs1.HeaderText = "TP-SM"
        cs1.NullText = ""
        cs1.ReadOnly = True
        cs1.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        dgProduct.TableStyles.Add(grdTableStyle)
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub
    Private Sub dgProduct_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgProduct.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgProduct.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgProduct.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgProduct.Select(hti.Row)
            Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
        End If
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        Me.Cursor = Cursors.WaitCursor
        Dim ds As DataSet = New DataSet("SerpsRpt")
        Dim table As DataTable = New DataTable("SerpsRpt")
        table.Columns.Add("Str1")
        table.Columns.Add("Str2")
        table.Columns.Add("Int1")
        table.Columns.Add("Int2")
        table.Columns.Add("Int3")
        table.Columns.Add("Int4")
        table.Columns.Add("Int5")
        table.Columns.Add("Int6")
        table.Columns.Add("Int7")
        table.Columns.Add("Int8")
        table.Columns.Add("Int9")
        table.Columns.Add("Int10")
        table.Columns.Add("Int11")
        table.Columns.Add("Int12")
        table.Columns.Add("Int13")
        table.Columns.Add("Int14")

        Dim mrow, drow As Integer
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.RowStateFilter = DataViewRowState.CurrentRows
        mrow = dv.Count
        'mrow = mrow - drow
        Dim ProdCode As String
        Dim ProdDesc As String
        Dim ProdQty As String

        Dim n As Integer
        For n = 0 To mrow - 1
            Dim nrow As DataRow = table.NewRow()
            nrow("Str1") = dgProduct.Item(n, 1)
            nrow("Str2") = dgProduct.Item(n, 2)
            nrow("Int1") = dgProduct.Item(n, 5)
            nrow("Int2") = dgProduct.Item(n, 6)
            nrow("Int3") = dgProduct.Item(n, 7)
            nrow("Int4") = dgProduct.Item(n, 8)
            nrow("Int5") = dgProduct.Item(n, 9)
            nrow("Int6") = dgProduct.Item(n, 10)
            nrow("Int7") = dgProduct.Item(n, 11)
            nrow("Int8") = dgProduct.Item(n, 12)
            nrow("Int9") = dgProduct.Item(n, 13)
            nrow("Int10") = dgProduct.Item(n, 14)
            nrow("Int11") = dgProduct.Item(n, 15)
            nrow("Int12") = dgProduct.Item(n, 16)
            nrow("Int13") = dgProduct.Item(n, 3)
            nrow("Int14") = dgProduct.Item(n, 4)
            table.Rows.Add(nrow)
        Next
        ds.Tables.Add(table)

        crICproductDistribution1.Load()
        crICproductDistribution1.SetDataSource(ds)

        crICproductDistribution1.SetParameterValue("CompanyName", CompanyTitle)

        If PrntPrv Is Nothing Then
            PrntPrv = New PrintPreviewForm
            PrntPrv.CrRptView.ReportSource = crICproductDistribution1
            PrntPrv.ShowDialog()
        End If
        crICproductDistribution1.Close()
        'crICproductDistribution1.PrintOptions.PrinterName = InvoicePrinter
        'Try
        '    iclistofpurchaseorder1.PrintToPrinter(1, True, 0, 0)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub cmbGroup1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If IsNumeric(cmbDepartment.SelectedValue) Then
            If cmbDepartment.SelectedValue > 0 Then
                Dim ICdata As New ICdataLogic
                Dim ds As DataSet
                ds = ICdata.GetBrandRelatedGroups(CompanyCode, 2, cmbDepartment.SelectedValue)
                cmbBrand.DataSource = ds.Tables(0)
                cmbBrand.ValueMember = "GroupID"
                cmbBrand.DisplayMember = "GroupName"
                cmbBrand.SelectedValue = 0
                '
                ds = ICdata.GetBrandRelatedGroups(CompanyCode, 3, cmbDepartment.SelectedValue)
                cmbManuf.DataSource = ds.Tables(0)
                cmbManuf.ValueMember = "GroupID"
                cmbManuf.DisplayMember = "GroupName"
                cmbManuf.SelectedValue = 0
                '
                ds = ICdata.GetBrandRelatedGroups(CompanyCode, 4, cmbDepartment.SelectedValue)
                cmbCategory.DataSource = ds.Tables(0)
                cmbCategory.ValueMember = "GroupID"
                cmbCategory.DisplayMember = "GroupName"
                cmbCategory.SelectedValue = 0
                '
                ds = ICdata.GetBrandRelatedGroups(CompanyCode, 5, cmbDepartment.SelectedValue)
                cmbSubCat.DataSource = ds.Tables(0)
                cmbSubCat.ValueMember = "GroupID"
                cmbSubCat.DisplayMember = "GroupName"
                cmbSubCat.SelectedValue = 0
                '
                ICdata = Nothing
            End If
        End If
    End Sub

    Private Sub cmdExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExport.Click
        SFdlg.DefaultExt = ".xls"
        SFdlg.Filter = "Excel files (*.xls)|*.xls"
        SFdlg.ShowDialog()
        Dim SaveFileName As String = ""
        SaveFileName = SFdlg.FileName
        If SaveFileName.Trim = "" Then
            MsgBox("File name should be selected !", MsgBoxStyle.Critical, "Inventory Manager")
            Exit Sub
        Else
            Dim mrow, drow As Integer
            Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
            Dim dv As DataView = cm.List
            dv.RowStateFilter = DataViewRowState.CurrentRows
            mrow = dv.Count
            Dim ICdata As New ICdataLogic
            ICdata.ExportDataToExcel(dgProduct, dgProduct.TableStyles(0), SaveFileName, mrow)
            ICdata = Nothing
        End If
        Dim item As DataGridCell
    End Sub

End Class
